<?php
/**
 * CONTENIDO extension pack (mpContenidoX), consists of multiple classes to
 * provide more features for Plugins/Modules.
 *
 * @package     mpContenidoX
 * @subpackage  Registry
 * @author      Murat Purc <murat@purc.de>
 * @copyright   Copyright (c) 2008-2012 Murat Purc (http://www.purc.de)
 * @license     http://www.gnu.org/licenses/gpl-2.0.html - GNU General Public License, version 2
 * @version     $Id: mpRegistry.class.php 21 2012-07-16 21:33:14Z purcaholic $
 */


defined('CON_FRAMEWORK') or die('Illegal call');


/**
 * Registry class to store and retrieve application wide objects
 *
 * @package     mpContenidoX
 * @subpackage  Registry
 * @author      Murat Purc <murat@purc.de>
 */
class mpRegistry
{
    /**
     * Registry storage container
     * @var  array
     */
    private static $_registry = null;


    /**
     * Registry item setter.
     *
     * @param   string  $name
     * @param   mixed   $value
     * @return  void
     */
    public static function set($name, $value)
    {
        self::$_registry[$name] = $value;
    }


    /**
     * Registry item getter.
     *
     * @param   string  $name
     * @return  mixed
     * @throws  Exception if registry key with passed $name doesn't exists.
     */
    public static function get($name)
    {
        if (!self::isRegistered($name)) {
            throw new Exception("No entry is registered for key '$name'");
        }
        return self::$_registry[$name];
    }


    /**
     * Checks if a registry key exists.
     *
     * @param   string  $name
     * @return  bool
     */
    public static function isRegistered($name)
    {
        if (self::$_registry === null || !isset(self::$_registry[$name])) {
            return false;
        }
        return true;
    }
}
